<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>OA协同办公系统</title>
		<link href="css/table.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="js/easyui/themes/default/easyui.css" />
		<link rel="stylesheet" href="js/easyui/themes/icon.css" />
		<script type="text/javascript" src="js/easyui/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript">
		$(function(){
             $('#tt2').tree({   
                  checkbox: false,   
                 url: 'organizationTree.action',   
                  onBeforeExpand:function(node,param){
                      $('#tt2').tree('options').url = "organizationChildTree.action?orgId="+ node.id;// change the url                       
                     
                  },               
                  onClick:function(node){
						$('#tt2').tree('options').url = "organizationChildTree.action?orgId="+ node.id;// change the url              
                       getOrg(node.id);
                  }   
              }); 

});
var list="";
var organization="";
function getOrg(id){
	var param={"pid":id};
	var parent="";
	var info="";
	$.post("getOrgByParent.action",param,function(data){
		var jsonobject= eval('(' + data + ')');
		 organization=jsonobject.org;
		 list=jsonobject.orgList;
		if(organization!=''&&organization!='null'){
			parent+="<input name=\"name\"  id=\""+organization.name+"\" type=\"radio\" value=\""+organization.id+"\" />"+organization.name+"";
		}else{
			parent+="无相关记录！";
		}
		if(list!=''&&list!='null'){
		for(var i=0;i<list.length;i++){
			info+="<tr><td align=\"left\"><input name=\"name\"  id=\""+list[i].name+"\" type=\"radio\" value=\""+list[i].id+"\"/>"+list[i].name+"</td></tr>";
		}
		}else{
			info+="<tr><td align=\"left\">无相关记录！</td></tr>";
		}
		$("#childOrg").html(info);
		$("#parentOrg").html(parent);
	});
}

function searchName(){
	var name=$("#name").val();
	if($.trim(name)==''||$.trim(name)=='null'){
		alert("请输入名称！");
		return;
	}
	var info="";
	var param={"name":name};
	$.post("getOrgByParent.action",param,function(data){
		var jsonobject= eval('(' + data + ')');
		 list=jsonobject.orgList;
		if(list!=''&&list!='null'){
		for(var i=0;i<list.length;i++){
			info+="<tr><td align=\"left\"><input name=\"name\" id=\""+list[i].name+"\" type=\"radio\" value=\""+list[i].id+"\"/>"+list[i].name+"</td></tr>";
		}
		}else{
			info+="<tr><td align=\"left\">无相关记录！</td></tr>";
		}
		$("#childOrg").html(info);
	});
}

function setValue(){
	var id="";
	var mame="";
	var flag=false;
	var radios=$("input[type=\"radio\"]");
	for(var i=0;i<radios.length;i++){
		if(radios[i].checked){
			id=radios[i].value;
			name=radios[i].id;
			flag=true;
			break;
		
		}
	}
	if(flag){
	  window.opener.addValue(id,name);
	  window.close();
	}else{
		alert("	请选择组织！");
	}
}
</script>
	</head>

	<body>
		<table align="center">
			<tr>
				<td>
					<div class="tiss_div">
						<ul class="uls">
							<li>
								组织名：
								<input type="text" id="name" style="width: 120px"
									class="input_search" />
							</li>
							<li>
								<input type="button" onclick="searchName()" class="button_04"
									value="搜索" />
							</li>
							<li>
								<input type="button" onclick="setValue()" class="button_04"
									value="添加" />
							</li>
						</ul>
					</div>

					<div class="tiss_menu" id="tree-div" style="overflow-y: auto; overflow-x: none;">
						<ul id="tt2">

						</ul>
					</div>
					<div class="tiss_menu2" style="overflow-y: auto; overflow-x: none;width: 330px">
						<h1 id="parentOrg"></h1>
						<table align="center" border="0" cellpadding="0" cellspacing="0" id="childOrg">
						</table>
					</div>

				</td>
			</tr>
		</table>
	</body>
</html>